#coding=utf-8
from uliweb import expose
from uliweb.orm import get_model

@expose('/')
def index():
    category=get_model('category')
    a=category(name="cat name")
    a.save()
    print a
    return '<h1>Hello, Uliweb</h1>'

@expose('/show/<id>')
def detail(id):
    con=get_model('con')
    q=con.get(con.c.id ==id)
    nid=int(id)+1
    next='<a href="/show/%s">NXTE</a>' % (nid)
    return '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'+'\n'+q.name+'<br>'+q.centon+'<br>'+next

@expose('/html')
def html():
    from bs4 import BeautifulSoup
    import hashlib
    html=get_html()
    soup = BeautifulSoup(html)
    revieweditems = soup.find(attrs={"class":"revieweditems mt10"})
    sub_cat=revieweditems.find_all(name="a", attrs={"class":"sub_category_name"})
    category=get_model('category')
    for scat in sub_cat:
        catm=category()
        catm.name=scat.string
        catm.url=scat.get('href')
        catm.url_code=hashlib.md5(catm.url).hexdigest().upper()
        catm.save()
    #print sub_cat
    return soup.title.string


